using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using Framework.Library.Components.Commands;
using Framework.Library.Components.Modules;
using Framework.Library.Components.Portal;
using Framework.Library.Components.Portal.Data;
using Framework.Library.Components.Roles;
using Framework.Library.Components.Tabs;
using Framework.Library.Components.Users;
using System.Data.SqlClient;

namespace Framework.Library.Components.Providers
{
	public abstract class DataAccessProvider
	{
        public DataAccessProvider() { }
		
		private static DataAccessProvider objProvider;

		public static DataAccessProvider Instance()
		{
			if (objProvider != null) return objProvider;
            DataAccessProviderConfiguration objConfig = DataAccessProviderConfiguration.GetDataAccessProviderConfiguration();
            objProvider = (DataAccessProvider)DataAccessProviderFactory.CreateDataAccess((Provider)objConfig.Providers[objConfig.DefaultProvider]);
            return objProvider;
        }        

        #region Portals
        public abstract PortalSetting GetPortalSetting();
        public abstract void SetPortalSetting(string settingName, string settingValue);
        public abstract void SetPortalSetting(string settingName, string settingValue, string param1, string param2);        
        public abstract Portal_PortalsInfo GetPortalsInfoByLang(int portalId);
        public abstract Portal_PortalsInfo GetPortalsById(int portalId);
        public abstract DataTable GetPortalsByParentId(int parentId);
        public abstract DataTable GetPortalsByParentId(int userid, int parentId);
        public abstract DataTable GetPortals();
        public abstract DataTable GetPortalsByUserID(int _userid);
        public abstract DataTable GetPortalsByLang(string lang);
        public abstract DataTable GetPortalsByLang(string lang, int level, int position);
        public abstract DataTable GetPortalsByLangLeft(string lang, int level, int position);
        public abstract DataTable GetPortalsByLangParent(string _lang, int Portal_ParentId);
        public abstract void DeletePortal(int portalId);
        public abstract int AddPortal(Portal_PortalsInfo portal);
        public abstract void UpdatePortal(Portal_PortalsInfo portal);
        #endregion

        #region Module
        public abstract DataTable GetModules(string Name, string Folder);
        public abstract DataTable GetModules();
        public abstract int AddModule(ModuleInfo module);
        public abstract void UpdateModule(ModuleInfo module);
        public abstract void DeleteModule(int moduleId);
        public abstract ModuleInfo GetModule(int moduleId);
        public abstract ModuleSetting GetModuleSettings(int moduleId);
        public abstract void SetModuleSetting(int moduleId, string name, string value);
        #endregion

        #region ModuleControls
        public abstract DataTable GetModuleControls();
        public abstract DataTable GetModuleControls(int moduleId);
        public abstract DataTable GetModuleControls(int tabId, string layoutPosition);
        public abstract DataTable GetModuleControlsForCommand();
        public abstract DataTable GetModuleControlsForWeb();        
        public abstract int AddModuleControl(ModuleControlInfo moduleControl);
        public abstract void UpdateModuleControl(ModuleControlInfo moduleControl);
        public abstract void DeleteModuleControl(int controlId);
        public abstract ModuleControlInfo GetModuleControl(int controlId);
        public abstract ModuleControlInfo GetModuleControl(string controlKey);
        public abstract bool CheckExistsControlKey(string controlKey);
        #endregion

        #region Roles
        public abstract DataTable GetRoles();
        public abstract DataTable GetRoles(string key, string searchby, string filter);
        public abstract DataTable GetRoles(int userId);
        public abstract int AddRole(RoleInfo role);
        public abstract void UpdateRole(RoleInfo role);
        public abstract void DeleteRole(int roleId);
        public abstract RoleInfo GetRole(int roleId);
        public abstract DataTable GetRolesByParentId(int parentId);
        public abstract void AddUserToRole(int userId, int roleId, int portalId);
        public abstract void UpdateUserToRole(int userId, int roleId, int portalId);
        public abstract void RemoveUserFromRole(int userId, int roleId, int portalId);
        public abstract void AddCommandToRoleByPortalID(int commandId, int roleId, int portalID);
        public abstract void RemoveCommandFromRoleByPortalID(int commandId, int roleId, int portalID);
        public abstract void UpdateRolePermissionByPortalID(int commandId, int roleid, int portalId, bool view, bool add, bool update, bool delete);
        #endregion     

        #region PortalCache
        public abstract int AddPortalCache(Portal_CacheInfo portal);
        public abstract DataTable GetPortalCacheByPortalIdAndZoneID(int portalId, int zoneid);
        public abstract void DeletePortalCache(Portal_CacheInfo info);
        #endregion

        #region Users
        public abstract UserInfo GetUser(string username);
        public abstract DataTable GetAllByPortal(int PortalID);
        public abstract UserInfo GetUser(int userId);
        public abstract DataTable GetUsers();
        public abstract DataTable GetUsers(int roleId, int portalId);
        public abstract DataTable GetUsers(string key, string searchby, string filter, int portalId);
        public abstract DataTable GetUsersByUser(string key, string searchby, string filter, int userid, int portalId);
        public abstract DataTable GetUsersNotInRole(int roleId, int portalId);        
        public abstract UserInfo ValidateUser(string username, string password);
        public abstract int AddUser(UserInfo user);
        public abstract void UpdateUser(UserInfo user);
        public abstract void EditUser(UserInfo user);
        public abstract void DeleteUser(int userId);  
        public abstract void AddCommandToUser(int commandId, int userId);
        public abstract void RemoveCommandFromUser(int commandId, int userId);
        public abstract void ResetPassword(int userId, string password);
        public abstract void ChangePassword(int userId, string oldPassword, string newPassword);
        public abstract void AddCommandToUserByPortalID(int commandId, int userId, int portalId);
        public abstract void RemoveCommandFromUserByPortalID(int commandId, int userId, int portalId);
        public abstract void UpdateUserPermissionByPortalID(int commandId, int userId, int portalId, bool view, bool add, bool update, bool delete);
        public abstract bool IsApproved(string strUsername);
        public abstract bool IsSuspended(string strUsername);
        #endregion                 

        #region Language
        public abstract DataTable GetAll();
        public abstract DataTable GetAll_Without_Current_Language(string lang);
        #endregion  
     
        #region Command
        public abstract DataTable GetCommands();
        public abstract DataTable GetCommandsForUserNotGroup(int userId, int portalId);
        public abstract DataTable GetCommandsForRoleByPortalID(int roleId, int portalID);
        public abstract DataTable GetCommandsForUserByPortalID(int userId, int portalID);
        public abstract int AddCommand(CommandInfo command);
        public abstract void UpdateCommand(CommandInfo command);
        public abstract void UpdateCommandbyControl(string old_cmd, string new_cmd);        
        public abstract void DeleteCommand(int commandId); // Delete command
        public abstract CommandInfo GetCommand(int commandId); // Get command info
        public abstract string GetCommandbyID(int commandId);
        public abstract CommandInfo GetCommand(string commandKey); // Get command info
        public abstract bool IsAvailableForUser(int commandId, int userId, int portalid);
        public abstract bool IsSystemModule(int commandId);
        public abstract DataTable GetButtonRoleForUserByPortalID(int userId, int portalID); // Get button role for instance user by portalid
        #endregion

        #region Tabs
        public abstract TabInfo GetTab(int tabId);
        public abstract DataTable GetTabs(string lang);
        public abstract DataTable GetTabs(int parent);
        public abstract DataTable GetTabs(bool visible, bool enable, string lang);
        public abstract DataTable GetTabsByPortalID(int portalID, string lang);
        public abstract TabControlInfo GetTabControl(int tabControlId);        
        public abstract int AddTab(TabInfo tab);
        public abstract void UpdateTab(TabInfo tab);
        public abstract void DeleteTab(int tabId);
        public abstract void AddControlToTab(int tabControlId, int tabId, int controlId, string layoutPosition, int order);
        public abstract void RemoveControlFromTab(int tabControlId);
        public abstract void UpdateTabControl(int tabControlId, int tabId, string layoutPosition, int order);
        #endregion

        #region Infomation
        public abstract DataTable GetDatabaseInfo();
        public abstract DataTable GetDatabaseConfiguration();
        public abstract DataTable GetOwners();
        public abstract DataTable GetFileGroups();
        public abstract DataTable GetDataTypes();
        public abstract DataTable GetDefaults();
        public abstract DataTable GetRules();
        #endregion

        #region Database 
        public abstract DataTable GetTables();
        public abstract DataTable GetColums(string tblName);
        public abstract void DropTable(string tblName);
        public abstract DataTable GetViews();
        public abstract DataTable GetStores();        
        public abstract SqlDataReader LoadProperty(long _ID);        
        #endregion

        public abstract void ExecuteCommand(string strSQL);
        public abstract SqlDataReader ReturnReader(string strSQL);
        public abstract DataTable ReturnDataSet(string strSQL);
        public abstract SqlCommand GetProcedureCommand(string procedureName);
    }
}
